<template>
  <div class="p-4">
    <BasicTable @register="registerTable">
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: '下载',
              icon: 'ant-design:download-outlined',
              onClick: handleDelete.bind(null, record),
            },

          ]"
        />
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicTable, useTable, BasicColumn, TableAction } from '/@/components/Table';

  import { demoListApi, Downloadfile } from '/@/api/learningcorner/table';
  import { string } from 'vue-types';
  import { getToken } from '/@/utils/auth';
  import { downloadByUrl } from '/@/utils/file/download';
import axios from 'axios';
  const columns: BasicColumn[] = [
    {
      title: '文件名',
      dataIndex: 'fileName',
    },
  ];
  export default defineComponent({
    components: { BasicTable, TableAction },
    setup() {
      const [registerTable] = useTable({
        title: '文件下载中心',
        api: demoListApi,
        columns: columns,
        rowSelection: { type: 'radio' },
        bordered: true,
        actionColumn: {
          width: 160,
          title: '下载',
          dataIndex: 'action',
          slots: { customRender: 'action' },
        },
      });
      function handleDelete(record: Recordable) {
        console.log('点击了删除', record.fileName);


        const file = record.fileName

        console.log(file)
        const token = getToken();
        console.log(token)


        handleDownloadByUrl(file)


      };
      function handleDownloadByUrl(file:string) {
        downloadByUrl({
          url: 'https://codeload.github.com/anncwb/vue-vben-admin-doc/zip/master',
          target: '_self',
        });

        downloadByUrl({
          url: 'http://localhost:8081/demo/download?file='+file,
          target: '_self',
        });
      }

      return {
        handleDownloadByUrl,
        registerTable,
        handleDelete,
      };
    },
  });
</script>
